<?php
include_once '../mysql/sql-feedback.php';

// 创建数据库
function create_sql(&$mysql, $params) {
    return sql_feedback('create database ' . $params["sqlname"], $mysql);
};

// 删除数据库
function drop_sql(&$mysql, $params) {
    return sql_feedback('drop database ' . $params["sqlname"], $mysql);
};

// 创建用户表
function create_users(&$mysql, $params) {
$statement = <<< EOT
create table users(
    id varchar(50) not null primary key,
    username varchar(20) not null,
    password varchar(20) not null,
    email varchar(30),
    phone varchar(11),
    sex varchar(10),
    birthday date,
    basemoney decimal(8,2) not null default 0.00
)engine=innodb default charset=utf8;
EOT;
    // echo '<hr />', $statement, '<hr />';
    return sql_feedback($statement, $mysql);
};

// 创建类型表
function create_types(&$mysql, $params) {
$statement = <<< EOT
create table types(
    typecode int not null primary key auto_increment,
    typename varchar(20) not null,
    incspe int not null,
    user varchar(50) not null references users(id)
)engine=innodb default charset=utf8;
EOT;
    // echo '<hr />', $statement, '<hr />';
    return sql_feedback($statement, $mysql);
};

// 创建记录表
function create_incspes(&$mysql, $params) {
$statement = <<< EOT
create table incspes(
    incspecode int not null primary key auto_increment,
    type varchar(50) not null references types(typecode),
    money decimal(7,2) not null,
    remark text,
    date date not null,
    user varchar(50) not null references users(id)
)engine=innodb default charset=utf8;
EOT;
    // echo '<hr />', $statement, '<hr />';
    return sql_feedback($statement, $mysql);
};

// 删除表
function delete_table(&$mysql, $params) {
$statement = <<< EOT
drop table incspes
EOT;
    // echo '<hr />', $statement, '<hr />';
    return sql_feedback('drop table ' . $params['tablename'], $mysql);
};
?>